package com.gxa.admin.recycling.config;


import com.gxa.core.recycling.interceptor.AdminInterceptor;
import com.gxa.core.recycling.interceptor.PermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * springboot使用拦截器的配置
 * @Configuration 表示当程序启动,
 * @author HS
 */
//swagger拦截有问题需要改进
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {


    @Resource
    AdminInterceptor adminInterceptor;
    /**
     * 利用WebMvcConfigurer提供的拦截器注册方法
     * 将自定义的PermissionInterceptor注册到spring拦截器体系中
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/swagger-ui/index.html")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/admin/logout");

    }

    /**
     * 执行方法并将方法的返回值作为bean,添加到spring容器
     * @return

     */
    @Bean("adminInterceptor")
    public AdminInterceptor createAdminInterceptor(){
        return new AdminInterceptor();
    }
}
